package ius.mantianx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @author starrysky
 * @title: ThyController
 * @projectName rev_thymeleaf_boot
 * @description: controller layer
 * @date 2021/2/800:20
 */
@Controller
@RequestMapping("/user")
public class ThyController {
    @PostMapping("/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model map, HttpSession session) {
        if (StringUtils.hasLength(username) && "123456".equals(password)) {
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";
        } else {
            map.addAttribute("msg", "账号或密码错误");
            return "/login";
        }
    }
}
